<template>
  <el-dialog
    title="上传抵押申请表"
    :close-on-click-modal="false"
    @close="closeHandle"
    v-loading="uploading"
    element-loading-text="正在上传抵押申请表"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
    :visible.sync="visible">
    <el-upload
      drag
      :action="url"
      ref="upload"
      :before-upload="beforeUploadHandle"
      :on-success="successHandle"
      :on-error="errHandle"
      :data="{seqno:this.seqno, fileCode:'01'}"
      :show-file-list="false"
      :limit="1"
      :file-list="fileList"
      style="text-align: center;">

      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <div class="el-upload__tip" slot="tip"></div>
    </el-upload>
  </el-dialog>



</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        url: '',
        seqno: 0,
        uploading: false,
        failDetail: [],
        fileList: []
      }
    },
    methods: {
      init (id) {
        this.fileList = [];
        this.seqno = id
        this.url = this.$http.adornUrl(`/bdc/bdcfirstregist/uploadDysqs?token=${this.$cookie.get('token')}`)
        this.visible = true         
      },
      // 上传之前
      beforeUploadHandle (file) {
        this.uploading = true
      },
      errHandle(response){
          this.$message.error(response.msg)
          this.$refs.upload.clearFiles()  
      },
      // 上传成功
      successHandle (response, file) {

        if (response && response.code === 0) {

              this.$message({
                message: "上传成功",
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              });

            
        } else {
          this.$message.error(response.msg)
        }
        this.$refs.upload.clearFiles()  
        this.uploading = false 
      },
      // 弹窗关闭时
      closeHandle () {

        // this.$emit('refreshDataList')
      }
    }
  }
</script>
